import os
import redis
from loguru import logger

redis_connect={
    "host":"newacademic.redis.rds.aliyuncs.com",
    "port":6379,
    "pwd":"sunyuwei:%syw123456",
    "db":10,
}

class RedisClient:

    def __init__(self):
        try:
            pool = redis.ConnectionPool(
                host=redis_connect['host'],
                port=redis_connect['port'],
                password=redis_connect['pwd'],
                decode_responses=True,
                db=redis_connect['db']
            )
            self.redis_pool = redis.StrictRedis(connection_pool=pool)
            logger.success('Redis连接成功')
        except Exception as e:
            logger.error(f'Redis连接失败,{e}')
            os._exit(0)

    def spop_md5(self,keyname):
        return self.redis_pool.spop(keyname)

    def kyes_name(self,re_name):
        return self.redis_pool.keys(re_name)


redis_client=RedisClient()